package com.kancy.delay.queue.redis.properties;

import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * DelayQueueProperties
 * <p>
 *
 * @author: kancy
 * @date: 2020/3/4 12:17
 **/
public class DelayQueueProperties {

    /**
     * 项目名称，作为命名空间使用
     */
    private String project;

    /**
     * 集群环境slot hash key prefix
     */
    private String slotKeyPrefix = "{key}";

    /**
     * 任务执行器属性
     */
    @NestedConfigurationProperty
    private TaskExecutorProperties executor = new TaskExecutorProperties();

    /**
     * 客户端属性
     */
    @NestedConfigurationProperty
    private ClientProperties client = new ClientProperties();

    /**
     * 服务端属性
     */
    @NestedConfigurationProperty
    private ServerProperties server = new ServerProperties();

    /**
     * 自定义topics
     */
    private Map<String, TopicProperties> topics = new HashMap<>();

    public String getProject() {
        return project;
    }

    public void setProject(String project) {
        this.project = project;
    }

    public String getSlotKeyPrefix() {
        return slotKeyPrefix;
    }

    public void setSlotKeyPrefix(String slotKeyPrefix) {
        this.slotKeyPrefix = slotKeyPrefix;
    }

    public ClientProperties getClient() {
        return client;
    }

    public void setClient(ClientProperties client) {
        this.client = client;
    }

    public ServerProperties getServer() {
        return server;
    }

    public void setServer(ServerProperties server) {
        this.server = server;
    }

    public Map<String, TopicProperties> getTopics() {
        return topics;
    }

    public void setTopics(Map<String, TopicProperties> topics) {
        this.topics = topics;
    }

    public TaskExecutorProperties getExecutor() {
        return executor;
    }

    public void setExecutor(TaskExecutorProperties executor) {
        this.executor = executor;
    }

    public static class ServerProperties{
        /**
         * 是否开启
         */
        private boolean enabled = true;

        /**
         * 初始化延迟启动时间
         */
        private Duration initialDelay = Duration.ofSeconds(3);

        /**
         * 扫描间隔，默认1s
         */
        private Duration scanInterval = Duration.ofSeconds(1);

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public Duration getInitialDelay() {
            return initialDelay;
        }

        public void setInitialDelay(Duration initialDelay) {
            this.initialDelay = initialDelay;
        }

        public Duration getScanInterval() {
            return scanInterval;
        }

        public void setScanInterval(Duration scanInterval) {
            this.scanInterval = scanInterval;
        }

    }

    public static class ClientProperties{
        /**
         * 是否开启
         */
        private boolean enabled = true;

        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
    }

}
